package ar.edu.caece.compiler.grammar.factories;

import ar.edu.caece.compiler.error.ErrorManager;
import ar.edu.caece.compiler.error.ParsingException;
import ar.edu.caece.compiler.grammar.AbstractTokenVisitorFactory;
import ar.edu.caece.compiler.grammar.Recognizer;
import ar.edu.caece.compiler.grammar.TokenRecognizer;
import ar.edu.caece.compiler.grammar.TokenVisitor;

import ar.edu.caece.compiler.grammar.attributes.StringAttribute;
import ar.edu.caece.compiler.grammar.nonterminals.REL3;
import ar.edu.caece.compiler.grammar.terminals.IgualToken;

public class REL3Factory extends AbstractTokenVisitorFactory {

	private static REL3Factory INSTANCE;
	
	public static REL3Factory getInstance() {
		if(INSTANCE==null) INSTANCE = new REL3Factory();
		return INSTANCE;
	}
	
	private REL3Factory() {
		
	}
	
	@Override
	public TokenVisitor makeChainedVisitor(
			final TokenVisitor siguiente) throws Exception {
		return new IgualToken.IgualChainVisitor(siguiente) {
			
			@Override
			public Recognizer igualCase(IgualToken llamador) {
				REL3 rel3 = new REL3(llamador);
				
				rel3.addAttribute("op",new StringAttribute("IGUAL"));
				return rel3;			}
		};
	
	}
	@Override
	public TokenVisitor makeVisitor() throws Exception {
		return new IgualToken.IgualTokenVisitor() {
			
			@Override
			public Recognizer defaultCase(TokenRecognizer llamador) throws Exception {
				ErrorManager.getInstance().manage(llamador,"REL3",new ParsingException("Error de parsing.",REL3.class,llamador));
				return null;
			}
			
			@Override
			public Recognizer igualCase(IgualToken llamador) {
				REL3 rel3 = new REL3(llamador);
				
				rel3.addAttribute("op",new StringAttribute("IGUAL"));
				return rel3;
			}
		};
	}
	
	
}
